package org.vt.scheduleapp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
	
	
public class LocPlotter extends MapActivity{
	private static final int ZOOM_LEVEL = 18;

	/** Called when the activity is first created. */
	//private static final String MAP_KEY = "0BpOKOGaNV--pQ-Km6inD4BSIY4viUJnBo6RViQ";

	private MapController mapController;
	private MapView mapView;
	private LocReader reader;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// Creating the map
		setContentView(R.layout.locationplot);
		mapView = (MapView) findViewById(R.id.mv);
		mapView.setBuiltInZoomControls(true);
		mapController = mapView.getController();
		mapController.setZoom(ZOOM_LEVEL);
		
		List<Overlay> mapOverlays = mapView.getOverlays();
		Drawable drawable = this.getResources().getDrawable(R.drawable.android);
		reader = new LocReader(this);
        List<Loc> locs= new ArrayList<Loc>();
		try {
			locs = reader.getAllLocs();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MapItemizedOverlay myOverlay = new MapItemizedOverlay(drawable, this);
		int lat;
		int lon;
		String lString;
		GeoPoint gp = null;
		OverlayItem oi = null;
		for(Loc loc: locs)
		{
			lat = (int)(loc.getLat()*1e6);
			lon = (int)(loc.getLon()*1e6);
			lString = "Lat: "+lat+", Lon: "+lon;
			gp = new GeoPoint(lat,lon);
			oi = new OverlayItem(gp, loc.getName(), lString);
			myOverlay.addOverlay(oi);
		}
		mapOverlays.add(myOverlay);
		mapController.animateTo(gp);
	}


	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
}
